﻿using System;
using System.Net.NetworkInformation;
using static System.Formats.Asn1.AsnWriter;

namespace _1222可以攻击国王的皇后
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            int[][] queens =
            {
                new int[] { 0, 1 },
                new int[] { 1, 0 },
                new int[] { 4, 0 },
                new int[] { 0, 4 },
                new int[] { 3, 3 },
                new int[] { 2, 4 },
            };
            int[] king = { 0, 0 };
            IList<IList<int>> ints = Solution.QueensAttacktheKing(queens, king);
        }
        public class Solution
        {
            //达成条件 同一行列 对角线
            public static IList<IList<int>> QueensAttacktheKing(int[][] queens, int[] king)
            {
                IList<List<int>> ints = new List<List<int>>();
                for (int i = 0; i < queens.Length; i++)
                {
                    int[] queen = queens[i];
                    int row = queen[0];
                    int column = queen[1];
                    Console.WriteLine($"Queen {i + 1}: Row {row}, Column {column}");


                    if (IsSameDiagonal(king[0], king[1], row, column))
                    {
                        List<int> result = new List<int>();
                        result.Add(row);
                        result.Add(column);
                        ints.Add(result);
                    }
                    else if (IsSameRowOrCloum(king[0], king[1], row, column))
                    {
                        List<int> result = new List<int>();
                        result.Add(row);
                        result.Add(column);
                        ints.Add(result);
                    }

                }
                return (IList<IList<int>>)ints;
            }
            /// <summary>
            /// 是否在同一对角线上
            /// </summary>
            /// <param name="king"></param>
            /// <param name="b"></param>
            /// <returns></returns>

            public static bool IsSameDiagonal(int row1, int col1, int row2, int col2)
            {
                int rowDiff = Math.Abs(row1 - row2);
                int colDiff = Math.Abs(col1 - col2);
                return rowDiff == colDiff;
            }

            public static bool IsSameRowOrCloum(int row1, int col1, int row2, int col2)
            {
                if (row1 == row2||col1 == col2)
                {
                    return true;
                }
                return false;
            }
        }
    }
}